package com.kang.controller;

import com.kang.service.ItemsService;
import com.kang.service.ShoppingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author 吃三明治派对中的康康
 * @Date 2022/4/30 11:29
 * @Version 1.0
 */
@Controller
public class GoodsMessController {

    @Autowired
    private ItemsService itemsService;
    @Autowired
    ShoppingService shoppingService;

    @RequestMapping("/goodsMess/{id}")
    public String goodsMess(Model model, @PathVariable long id){

        model.addAttribute("goodsMessage",itemsService.selectGoodsById(id));

        return "goodsMess";
    }

    @RequestMapping("/addShopping/{gid}")
    public String addShopping(@PathVariable long gid, HttpServletRequest request){
        if(request.getSession().getAttribute("UserSession") == null){
            return "redirect:/toLogin";
        }
        shoppingService.addShoppingByGid(gid);
        return "redirect:/shopping";
    }
}
